#!/bin/bash

echo "My name is Rich" | gawk '{$4="Christine"; print $0}'

# gawk选项
# F 指定分隔符
# f 指定script文件

# gawk默认使用空白字符作为分割符号，$1表示第一个结果，$2表示第二个结果，以此类推
# 特别地$0表示原始内容
# ➜  les8 git:(master) ✗ echo "My name is Rich" | awk '{print $0}' 
# My name is Rich
# ➜  les8 git:(master) ✗ echo "My name is Rich" | awk '{print $1}'
# My
# ➜  les8 git:(master) ✗ echo "My name is Rich" | awk '{print $2}'
# name
# ➜  les8 git:(master) ✗ echo "My name is Rich" | awk '{print $3}'
# is
# ➜  les8 git:(master) ✗ echo "My name is Rich" | awk '{print $4}'
# Rich
# ➜  les8 git:(master) ✗ echo "My name is Rich" | awk '{$4="Christine"; print $0}'
# My name is Christine

# gawk指定某个文件作为script
# ➜  les8 git:(master) ✗ cat gawkscript.gawk 
# {print $1 "'s home directory is: "$6}%       
# ➜  les8 git:(master) ✗ gawk -F: -f gawkscript.gawk /etc/passwd 
# nobody's home directory is: /var/empty
# root's home directory is: /var/root
# daemon's home directory is: /var/root
# _uucp's home directory is: /var/spool/uucp
# _taskgated's home directory is: /var/empty
